package com.solocredit.finance.ui.user.adapter

import android.graphics.Color
import android.widget.LinearLayout
import androidx.recyclerview.widget.RecyclerView
import com.solocredit.finance.R
import com.solocredit.finance.app.MyApp
import com.solocredit.finance.base.adapter.MullaRecyclerViewAdapter
import com.solocredit.finance.base.adapter.MullaViewHolderHelper
import org.json.JSONObject

/**
 * MullaFlow
 * @Author wwdeng
 * @CreateTime: 2024/8/13 17:07
 * @Annotation：用户签到列表
 */
class MullaUserSignDayAdapter(recyclerView: RecyclerView?) : MullaRecyclerViewAdapter<JSONObject>(recyclerView) {

    override fun getItemViewType(position: Int): Int {
        val model = getItem(position)
        if (position == 6){
            return R.layout.item_mulla_user_sign_gift
        }
        return R.layout.item_mulla_user_sign_day
    }

    override fun setItemChildListener(helper: MullaViewHolderHelper, viewType: Int) {
        helper.setItemChildClickListener(R.id.itemLayout) //点击Item
    }

    override fun fillData(helper: MullaViewHolderHelper, position: Int, model: JSONObject) {
        val textDay = helper.getTextView(R.id.textDay)
        textDay.text = String.format(MyApp.app.getString(R.string.user_check_in_day),"${position+1}")

        if (position != 6){
            val itemLayout = helper.getView<LinearLayout>(R.id.itemLayout)
            val imgStatus = helper.getImageView(R.id.imgStatus)
            if (model.optBoolean("isSign",false)){
                itemLayout.setBackgroundResource(R.drawable.mulla_radius_fill_fff0f0f0_12)
                textDay.setTextColor(Color.parseColor("#FFC8C8C8"))
                imgStatus.setImageResource(R.mipmap.mulla_user_check_in_signed_normal)
            } else {
                itemLayout.setBackgroundResource(R.drawable.mulla_radius_fill_fff7f7f5_12)
                textDay.setTextColor(Color.parseColor("#FF222222"))
                imgStatus.setImageResource(R.mipmap.mulla_user_check_in_signed_selected)
            }
        }
    }
}